/**
 *  唤醒APP方法
 *      contentType    内容类型
 *          1-普通直播；2-秀场直播；3-视频；4-专辑；5-专题；6-频道主页（普通频道、秀场频道）；7-文章；8-图集；9-音频；0-其他
 *      contentParam 内容参数
 *          内容类型为4,0,7,8,9时，该参数为完整的页面地址；其他类型均为相关内容id
 *       infoParmas json数据，复杂参数
 *       内容类型为7,8,9时需要填写
 */
window.openDownPage = function (contentType, contentParam,infoParmas) {
    // alert("contentType:" + contentType + ";contentParam:" + contentParam);
    // appurl: 唤醒APP成功后在APP中打开相应页面的地址
    let appurl = getAppUrl(contentType, contentParam,infoParmas);
    let tempurl = base64Encode(appurl);

    //tempurl中+，=等着3个符号是特殊符号会导致获取参数失败，所以此处做了一个替换
    tempurl = tempurl.replace(/\//g, "_a").replace(/\+/g, "_b").replace(/\=/g, "_c");

    //现网 //share.96189.com", //测试网 //testkfw.butel.com:81
    let host = sharebaseUrl;
    location.href = host + "plug/yfapp.html?appurl=" + tempurl;
};

window.base64Encode = function (str) {
    let rv;
    rv = encodeURIComponent(str);
    rv = unescape(rv);
    rv = window.btoa(rv);
    return rv;
};

// 获取appurl
function getAppUrl(contentType, contentParam,infoParmas) {
    let appurl = "";
    let paramobj;
    switch (contentType) {
        case 1 :
            appurl = "yfapp://redirectPage/?page=liveDetail&params=";
            paramobj = {programid: contentParam};// 节目id
            appurl = appurl + encodeURIComponent(JSON.stringify(paramobj));
            break;
        case 2 :
            appurl = "yfapp://redirectPage/?page=liveShow&params=";
            paramobj = {programid: contentParam};// 节目id
            appurl = appurl + encodeURIComponent(JSON.stringify(paramobj));
            break;
        case 3 :
            appurl = "yfapp://redirectPage/?page=video&params=";
            paramobj = {videoid: contentParam};// 视频id
            appurl = appurl + encodeURIComponent(JSON.stringify(paramobj));
            break;
        case 4 :
            appurl = "yfapp://redirectPage/?page=albumDetail&params=";
            paramobj = {albumDetailUrl: contentParam};
            appurl = appurl + encodeURIComponent(JSON.stringify(paramobj));
            break;
        case 5 :
            appurl = "yfapp://redirectPage/?page=subjectDetail&params=";
            paramobj = {subjectId: contentParam};// 专题id
            appurl = appurl + encodeURIComponent(JSON.stringify(paramobj));
            break;
        case 6 :
            appurl = "yfapp://redirectPage/?page=channelMain&params=";
            paramobj = {channelid: contentParam};// 频道id
            appurl = appurl + encodeURIComponent(JSON.stringify(paramobj));
            break;
        case 7:
        case 8:
        case 9:
            appurl = "yfapp://redirectPage/?page=newsDetail&params=";
            paramobj = {
                id: contentParam,// 内容id
                newsUrl:infoParmas.url,
                channelId:infoParmas.channelid,
                channelName:infoParmas.channelname,
                type:infoParmas.type
            };
            console.log(appurl +JSON.stringify(paramobj));
            appurl = appurl + encodeURIComponent(JSON.stringify(paramobj));
            break;
        default :
            appurl = "yfapp://redirectPage/?page=newsDetail&params=";
            appurl = appurl + encodeURIComponent(contentParam);
    }
    // alert("appurl:" + appurl);
    return appurl;
}
